
function btninit(){
	  $('input.btn').hover(function(){
		  $(this).addClass('btn-h');
	  },function(){
		  $(this).removeClass('btn-h');
	  });
		
	  $('input.btn-4').hover(function(){
		  $(this).addClass('btn-4-h');
	  },function(){
		  $(this).removeClass('btn-4-h');
	  });
	  
}

function posinit(){
    $('#header').PositionFixed('lefttop');  
    $("#cat").PositionFixed('topmiddle');    
    $('#loading').PositionFixed({left:'0px',top:'56px'});  
    $('#opt-bar').PositionFixed({left:'0px',top:'138px'});  

    $('#to-top').topLink({
	    min: 400,
	    fadeSpeed: 500
	});

  $('#to-top').click(function(e) {
    e.preventDefault();
    $.scrollTo(0,300);
  });
  
  $('#loading').ajaxStart(function() {
	  $(this).show();
  });	  
  
  $('#loading').ajaxComplete(function() {
	  $l = $(this);
	  setTimeout(function(){
		  $l.fadeOut();
	  },500);
  });	  
  
  $("a.cb").colorbox();
  $("a.cb-media").colorbox({iframe:true});
  
  
}

/****************ajax form ********************/
function ajaxinit(){
	
	$(".btn-ajax-submit").unbind("click"); 
	$('.btn-ajax-submit').click(btn_ajax_submit = function(){
		var $btn = $(this);
		$btn.unbind('click');
		var $frm = $('#'+$(this).attr('frmid'));
		
		var method = $frm.attr('method');
		if((typeof method) == "undefined"){
			method = 'POST';
		} 

		var datatype = $frm.attr('datatype');
		if((typeof datatype) == "undefined"){
			datatype = 'json';
		} 

		var action = $frm.attr('action');
		if(typeof action == "undefined"){
			alert('action is undefine!');
    		$btn.bind('click',btn_ajax_submit);
			return;
		} 
		
		var submitbefor = $frm.attr('submitbefor');
		if((typeof submitbefor) != "undefined"){
			var flag_befor = window[submitbefor]($frm);
			if(!flag_befor){
	    		$btn.bind('click',btn_ajax_submit);
				return false;
			} 
		} 
		action = action + '&tmp='+(new Date()).valueOf();
		$.ajax({
			type: method,
			url: action,
			data:$frm.serialize(),
			async: true,
			cache:false,
			dataType:datatype,
			success: function(msg){
	    		var submitafter = $frm.attr('submitafter');
	    		if((typeof submitafter) != "undefined"){
	    			var flag = window[submitafter](msg,$frm);
	    			if(flag){
	    				ajax_back(msg);
	    			}
	    		}else{
	    			ajax_back(msg);
	    		} 
	    		setTimeout(function(){
	    			$btn.bind('click',btn_ajax_submit);
	    		},300);
			}
		});		
	});    	
	
	$(".btn-ajax").unbind("click"); 
	$('.btn-ajax').click(btn_ajax = function(){
		$btn = $(this);

		var url = $(this).attr('href');
		var $elt = $(this);
		
		var befordo = $elt.attr('befordo');
		if((typeof befordo) != "undefined"){
			if(!window[befordo]($elt)){
				return false;
			}
		} 

		$.ajax({
			type: 'get',
			url: url,
			async: false,
			dataType:'json',
			success:function(msg){
	    		var afterdo = $elt.attr('afterdo');
	    		if((typeof afterdo) != "undefined"){
	    			if(window[afterdo](msg,$elt)){
	    				ajax_back(msg);
	    			}
	    			return;
	    		} 
	    		ajax_back(msg);
			}
		});		
		return false;
		
	});
	
	$(".btn-ajax-confirm").unbind("click"); 
	$('.btn-ajax-confirm').click(btn_ajax_confirm = function(){

		$btn = $(this);
		$btn.unbind('click');
		
		var url = $(this).attr('href');
		var $elt = $(this);
		var msg = $(this).attr('msg');

		asyncbox.confirm(msg,'警 告',cf = function(action){
　　　      		if(action == 'ok'){
　　　      			$.ajax({
　　　      				type: 'get',
　　　      				url: url,
　　　      				async: false,
　　　      				dataType:'json',
　　　      				success:function(msg){
　　　      		    		var afterdo = $elt.attr('afterdo');
　　　      		    		if((typeof afterdo) != "undefined"){
　　　      		    			if(window[afterdo](msg,$elt)){
　　　      		    				ajax_back(msg);
　　　      		    			}
  				    		$btn.bind('click',btn_ajax_confirm);

　　　      		    			return;
　　　      		    		} 
　　　      		    		ajax_back(msg);
　　　      				}
　　　      			});		
　　　      		}
		});		
		$btn.bind('click',btn_ajax_confirm);
		return false;
		
	});
	
	$('.wm-ajax').unbind('click');
	$('.wm-ajax').click(function(){
		$elt = $(this);
		var title = $elt.attr('wmtitle');
		var w = $elt.attr('wmw');
		var h = $elt.attr('wmh');
		var url = $elt.attr('href');
		
		var opt = {};
		opt.modal = true;
		opt.title = title;
		opt.width = w;
		opt.height = h;
		
		if($elt.attr('wmid')){
			opt.id = $elt.attr('wmid')
		}
		
		$.ajax({
		   type: "GET",
		   url: url,
		   async: false,
		   dataType:'html',
		   success: function(msg){
			   opt.html = msg;
			   asyncbox.open(opt);
		   }
		});		
		return false;
	});
	
	$('.btn-ajax-load').unbind('click');
	$('.btn-ajax-load').click(function(){
		$elt = $(this);
		var url = $elt.attr('href');
		var container = $elt.attr('alc');
		
		var befordo = $elt.attr('befordo');
		var afterdo = $elt.attr('afterdo');
		
		if((typeof befordo) != "undefined"){
			if(!window[befordo]($elt)){
				return false;
			}
		} 
		$.ajax({
		   type: "GET",
		   url: url,
		   async: false,
		   dataType:'html',
		   success: function(msg){
			   
	    		if((typeof afterdo) != "undefined"){
	    			if(window[afterdo](msg,$elt)){
	    				ajax_back(msg);
	    			}
	    			return false;
	    		} 
			   $(container).empty().html(msg);
			   return false;
		   }
		});		
		
		return false;
	});
	
}


function ajax_back(msg){
	if(msg.status == 'unlogin'){
		$('#btn-login').click();
	}else{
		if(msg.status == 'succ' && msg.msg.length != 0){
			asyncbox.tips(msg.msg,'success');
		}else if(msg.status == 'fail' && msg.msg.length != 0){
			asyncbox.tips(msg.msg,'error');
		}

	  setTimeout(function(){
		  	if(msg.href.length != 0){
				if(msg.href == 'reload'){
					window.location.reload();
				}else{
					window.location.href = msg.href;
				}
			}
	  },300);
			
	}
	
}

/***数据处理验证***/
String.prototype.trim= function(){  
    return this.replace(/(^\s*)|(\s*$)/g, "");  
};

function vUrl(p){
	var checkfiles=new RegExp("((^http)|(^https)|(^ftp)):\/\/(\\w)+\.(\\w)+");
	return checkfiles.test(p);
}

function isEmail(strEmail){
    if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
} 

function isUpass(upass){

	if (upass.search(/^[a-z0-9_-]{6,18}$/) != -1)
		return true;
	else
		return false;
}

function ajustH(iframe){
	var bh = $(iframe).contents().find('body').height();
	$(iframe).css('height',bh);
}

/***新窗口打开***/
function playpop(id) { 
	window.open ("http://www.xiami.com/song/play?ids=/song/playlist/id/"+id+"/object_name/default/object_id/0", "newwindow", "height=550, width=750, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no")
}